#!/usr/bin/env node

const http = require('http'); // 使用http模块
const cheerio = require('cheerio');

const url = 'http://www.edu2act.cn/team/21-ji-shu-ju-ku-yuan-li/';

http.get(url, (res) => {
  let data = '';

  res.on('data', (chunk) => {
    data += chunk;
  });

  res.on('end', () => {
    const $ = cheerio.load(data);
    // console.log(data, $)
    const tasks = [];

    $('.task-list-item-wrap .flex-1').each((index, element) => {
      const taskName = $(element).find('.f4').text().trim();
      const startTime = $(element).find('.d-flex .ml-2 span').text().trim().substring(4);
      const toVerify = $(element).find('.d-flex .mt-2 span').eq(0).text().trim();
      const unfinished = $(element).find('.d-flex .mt-2 span').eq(1).text().trim();
      const accepted = $(element).find('.d-flex .mt-2 span').eq(2).text().trim();

      tasks.push({
        taskName,
        startTime,
        toVerify,
        unfinished,
        accepted
      });
    });

    console.log('作业任务列表：');
    tasks.forEach(task => {
      console.log(`任务名称: ${task.taskName}`);
      console.log(`开始时间: ${task.startTime}`);
      console.log(`待验证数: ${task.toVerify}`);
      console.log(`未完成数: ${task.unfinished}`);
      console.log(`已验收数: ${task.accepted}`);
      console.log('------------------');
    });
  });
}).on('error', (err) => {
  console.error('请求遇到问题:', err);
});